#!/usr/bin/env python
# -*- coding: utf-8 -*-
#  emailManager.py
#  description

#  Created by zhouzongli633 on 2020/6/29 2:44 下午.
#  Copyright ©Intellectus All rights reserved.
import smtplib
from email.mime.text import MIMEText


class Hotmail(object):

    def __init__(self, account, password):
        self.account = "%s@Hotmail.com" % account
        self.password = password

    def send(self, to, frm, subject, content):
        # print(self.account, self.password)
        server = smtplib.SMTP('smtp.live.com')
        server.docmd("EHLO server")
        server.starttls()
        server.login(self.account, self.password)

        msg = MIMEText(content)
        msg['Content-Type'] = 'text/plain; charset="utf-8"'
        msg['Subject'] = subject
        msg['From'] = self.account
        msg['To'] = to
        server.sendmail(self.account, to, msg.as_string())
        server.close()


def send_invitation_code(email, security_code, full_name, member_email, member_full_name):
    mailer = Hotmail("fjlylczzl", "Zongli1314!")
    content = 'Hi,{},your invitation code is:{}'.format(full_name, security_code)
    frm = '{}({})'.format(member_full_name, member_email)
    subject = 'Welcome to SMART NICU2HOME!'
    mailer.send(email, frm, subject, content)


def send_password_reset(email, password):
    new_password = password
    # mail(to: email_address, subject: 'Password reset')
    pass


if __name__ == "__main__":
    Hotmail = Hotmail("fjlylczzl", "")
    context = "context\r\nthis some text in email body\r\n" \
              "this some text in email body\r\nthis some text in email body\r\n"
    Hotmail.send("carol.zheng@intellectus.com", "nicu2home", context)
